<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Website Maker</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Website Maker' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="index.html">inblorb</a></li><li><a href="index.html#3">Chapter 3: Other Material</a></li><li><b>Website Maker</b></li></ul></div>
<p class="purpose">To accompany a release with a mini-website.</p>

<ul class="toc"><li><a href="3-wm.html#SP1">&#167;1. Landmarks in the source</a></li><li><a href="3-wm.html#SP3">&#167;3. Styling with CSS</a></li><li><a href="3-wm.html#SP9">&#167;9. Making an HTML page from a template</a></li><li><a href="3-wm.html#SP11">&#167;11. Rendering the source text as HTML pages</a></li><li><a href="3-wm.html#SP12">&#167;12. Pass 1: scanning the source for tables and headings</a></li><li><a href="3-wm.html#SP15">&#167;15. Pass 2: writing the source text pages</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Landmarks in the source.</b>Making a website is not especially tricky. The difficult part is typesetting
the source text into it, if that's been requested. We will need to do that by
scanning the source text for typographically significant structures:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">ABBREVIATED_HEADING_LENGTH</span><span class="plain-syntax"> </span><span class="constant-syntax">1000</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_line_start</span><span class="plain-syntax">; </span><span class="comment-syntax"> line number in the source where the table heading appears</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_line_end</span><span class="plain-syntax">; </span><span class="comment-syntax"> line number of the blank line which marks the end of the table body</span>
<span class="plain-syntax">    </span><span class="constant-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">table</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">heading</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">heading_line</span><span class="plain-syntax">; </span><span class="comment-syntax"> line number in the source at which the heading appears</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">heading_level</span><span class="plain-syntax">; </span><span class="comment-syntax"> a low number makes this a more significant heading than a high number</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">heading_has_content</span><span class="plain-syntax">; </span><span class="comment-syntax"> is there anything other than white space before the next heading?</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">heading_to_segment</span><span class="plain-syntax">; </span><span class="comment-syntax"> which segment contains the heading</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">heading_text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">heading</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure table is private to this section.</li><li>The structure heading is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Segments are used to divide the source text into pieces of what we hope will
be a manageable size.
</p>

<p class="commentary">It is not true that the source text is partitioned exactly by segments. The
topmost segment begins at the first heading in the source text. So there
will usually be at least a few prefatory lines before this point &mdash; perhaps
the title, some extension inclusions, and so on &mdash; and it's even possible,
if there are no headings at all, for there to be no segments so that the
entire source text is "prefatory". If we have three segments, then, we
will split the source text into four HTML files:
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">source0.html</span></span> &mdash; "Page 1 of 4", the preface and then contents
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">source1.html</span></span> &mdash; "Page 2 of 4", first segment (with allocation ID 0)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">source2.html</span></span> &mdash; "Page 3 of 4", second segment (with allocation ID 1)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">source3.html</span></span> &mdash; "Page 4 of 4", third segment (with allocation ID 2)
</p>

<p class="commentary">Note that the prefatory lines contain no headings, that every heading
belongs to a unique segment (hence the <span class="extract"><span class="extract-syntax">heading_to_segment</span></span> field above)
and that the top line of every segment is always a heading. A single
segment can contain multiple headings, because we run on a heading if it
contains no content except white space: this is so that, e.g.,
</p>

<blockquote>
    <p>Part I - Up the Amazon</p>
</blockquote>

<blockquote>
    <p>Section I.1 - The lower delta</p>
</blockquote>

<blockquote>
    <p>Rickety Jetty is a room. [...]</p>
</blockquote>

<p class="commentary">would be combined into a single segment, rather than a pointlessly short
segment just containing the "Part I" heading followed by a second segment
opening with "Section I.1".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">begins_at</span><span class="plain-syntax">; </span><span class="comment-syntax"> line number on which the segment begins</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">ends_at</span><span class="plain-syntax">; </span><span class="comment-syntax"> line number of the last line of the segment, or </span><span class="extract"><span class="extract-syntax">MAX_SOURCE_TEXT_LINES</span></span><span class="comment-syntax"> if it runs to the end</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">documentation</span><span class="plain-syntax">; </span><span class="comment-syntax"> is this in the documentation of an extension?</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> </span><span class="identifier-syntax">start_position_in_file</span><span class="plain-syntax">; </span><span class="comment-syntax"> within the source text</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">most_recent_heading</span><span class="plain-syntax">; </span><span class="comment-syntax"> or </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> if there hasn't been one</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">most_recent_table</span><span class="plain-syntax">; </span><span class="comment-syntax"> or </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> if there hasn't been one</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">segment_url</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">link_home</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">link_contents</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">link_previous</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">link_next</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">page_number</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">segment</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure segment is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Styling with CSS.</b>We try to give the template files as much freedom as possible to define
whatever CSS styles they need, but the template can't see inside the text of
variables, so Inblorb itself has to choose CSS styles for anything interesting
that is displayed there. We use the following style names, which a CSS file
is required to define:
</p>

<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">columnhead</span></span> &mdash; the heading of a column in a Table in I7 source text
</li><li>(b) <span class="extract"><span class="extract-syntax">comment</span></span> &mdash; comments in I7 source text
</li><li>(c) <span class="extract"><span class="extract-syntax">filetype</span></span> &mdash; the "(pdf, 150KB)" text annotating links
</li><li>(d) <span class="extract"><span class="extract-syntax">heading</span></span> &mdash; heading or top line of a Table in I7 source text
</li><li>(e) <span class="extract"><span class="extract-syntax">i6code</span></span> &mdash; verbatim I6 code in I7 source text
</li><li>(f) <span class="extract"><span class="extract-syntax">notecue</span></span> &mdash; footnote cues which annotate I7 source text
</li><li>(g) <span class="extract"><span class="extract-syntax">notesheading</span></span> &mdash; the little "Notes" subheading above the footnotes to source text
</li><li>(h) <span class="extract"><span class="extract-syntax">notetext</span></span> &mdash; texts of footnotes which annotate I7 source text
</li><li>(i) <span class="extract"><span class="extract-syntax">quote</span></span> &mdash; double-quoted text in I7 source text
</li><li>(j) <span class="extract"><span class="extract-syntax">substitution</span></span> &mdash; text substitution inside double-quoted text in I7 source text
</li></ul>
<p class="commentary">In addition it must provide paragraph classes <span class="extract"><span class="extract-syntax">indent0</span></span> to <span class="extract"><span class="extract-syntax">indent9</span></span> for code
which begins at tab positions 0 to 9 (see below). Although "Standard.css"
contains other names of classes, these are only needed because "Standard.html"
or "Standard-Source.html" say so: Inblorb does not mandate them.
</p>

<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>In case CSS is not available, we use old-fashioned HTML alternatives:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::open_style</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Websites::open_style</span></span>:<br/><a href="3-wm.html#SP5">&#167;5</a>, <a href="3-wm.html#SP20_2">&#167;20.2</a>, <a href="3-wm.html#SP22_3">&#167;22.3</a>, <a href="3-wm.html#SP22_4_1">&#167;22.4.1</a>, <a href="3-wm.html#SP22_4_7_3_1">&#167;22.4.7.3.1</a><br/>Links and Auxiliary Files - <a href="3-laaf.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">char</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;span class=\"%s\"&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">new</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"columnhead"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;u&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"comment"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#404040&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"filetype"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;small&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"heading"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;b&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"i6code"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#909090&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"notecue"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#404040&gt;&lt;sup&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"notesheading"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;i&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"notetext"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#404040&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"quote"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#000080&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="string-syntax">"substitution"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;font color=#000080&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::close_style</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Websites::close_style</span></span>:<br/><a href="3-wm.html#SP5">&#167;5</a>, <a href="3-wm.html#SP20_2">&#167;20.2</a>, <a href="3-wm.html#SP22_3">&#167;22.3</a>, <a href="3-wm.html#SP22_4_2">&#167;22.4.2</a>, <a href="3-wm.html#SP22_4_7_3_1">&#167;22.4.7.3.1</a><br/>Links and Auxiliary Files - <a href="3-laaf.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">char</span><span class="plain-syntax"> *</span><span class="identifier-syntax">old</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/span&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"columnhead"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/u&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"comment"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"filetype"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/small&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"heading"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/b&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"i6code"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"notecue"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/sup&gt;&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"notesheading"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/i&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"notetext"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"quote"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">strcmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">old</span><span class="plain-syntax">, </span><span class="string-syntax">"substitution"</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/font&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>In what follows, we will need to have a current typographic style for text,
and may need to change it at any point inside the paragraph. We represent the
current style by the global variable <span class="extract"><span class="extract-syntax">current_style</span></span>, which is either <span class="extract"><span class="extract-syntax">NULL</span></span>
(for ordinary text) or the name of one of the styles above.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">char</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_style</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::change_style</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Websites::change_style</span></span>:<br/><a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>, <a href="3-wm.html#SP22_4_7_2">&#167;22.4.7.2</a>, <a href="3-wm.html#SP22_4_7_3">&#167;22.4.7.3</a>, <a href="3-wm.html#SP22_4_7_4">&#167;22.4.7.4</a>, <a href="3-wm.html#SP22_4_7_5">&#167;22.4.7.5</a>, <a href="3-wm.html#SP22_4_7_6">&#167;22.4.7.6</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">char</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_style</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_style</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">new</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_style</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>We also use CSS to manage code indentation, when it's available, since this
can handle hanging indentation much better.
</p>

<p class="commentary">The block of source text displayed on a web page should be framed within:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::open_code</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Websites::open_code</span></span>:<br/><a href="3-wm.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;p&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::close_code</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Websites::close_code</span></span>:<br/><a href="3-wm.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/p&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>Each individual paragraph of the source text (which looks like a line to us)
should then be framed within:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::open_code_paragraph</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Websites::open_code_paragraph</span></span>:<br/><a href="3-wm.html#SP22_4">&#167;22.4</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">indentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">char</span><span class="plain-syntax"> *</span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">""</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">indentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent0"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent1"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent2"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent3"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent4"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">5</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent5"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">6</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent6"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">7</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent7"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">8</span><span class="plain-syntax">: </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent8"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">classname</span><span class="plain-syntax"> = </span><span class="string-syntax">"indent9"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;p class=\"%s\"&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">classname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">indentation</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::close_code_paragraph</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Websites::close_code_paragraph</span></span>:<br/><a href="3-wm.html#SP22_4">&#167;22.4</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/p&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;br&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>In the age of CSS, old-fashioned elements like <span class="extract"><span class="extract-syntax">halign</span></span> for individual table
cells are deprecated, so:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::open_table_cell</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Websites::open_table_cell</span></span>:<br/><a href="3-wm.html#SP22_4">&#167;22.4</a>, <a href="3-wm.html#SP22_4_7_1">&#167;22.4.7.1</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;td&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;td halign=\"left\" valign=\"top\"&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::close_table_cell</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Websites::close_table_cell</span></span>:<br/><a href="3-wm.html#SP22_4">&#167;22.4</a>, <a href="3-wm.html#SP22_4_7_1">&#167;22.4.7.1</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">use_css_code_styles</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/td&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&amp;nbsp;&amp;nbsp;&lt;/td&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Making an HTML page from a template.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::web_copy</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Websites::web_copy</span></span>:<br/><a href="3-wm.html#SP15_3">&#167;15.3</a>, <a href="3-wm.html#SP15_4">&#167;15.4</a><br/>Main - <a href="1-mn.html#SP7">&#167;7</a><br/>Releaser - <a href="3-rls.html#SP9_1">&#167;9.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">from</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">to</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">from</span><span class="plain-syntax"> == </span><span class="identifier-syntax">to</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><a href="1-be.html#SP2" class="function-link"><span class="function-syntax">BlorbErrors::fatal</span></a><span class="plain-syntax">(</span><span class="string-syntax">"files confused in website maker"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> </span><span class="identifier-syntax">TO_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax"> = &amp;</span><span class="identifier-syntax">TO_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">STREAM_OPEN_TO_FILE</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="constant-syntax">UTF8_ENC</span><span class="plain-syntax">) == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><a href="1-be.html#SP3" class="function-link"><span class="function-syntax">BlorbErrors::error_1f</span></a><span class="plain-syntax">(</span><span class="string-syntax">"unable to open file to be written for web site"</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">HTML_pages_created</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><a href="../foundation/4-tf.html#SP5" class="function-link"><span class="function-syntax">TextFiles::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><span class="string-syntax">"can't open template file"</span><span class="plain-syntax">, </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line</span></a><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">STREAM_CLOSE</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>Each line in turn comes here, then.
</p>

<p class="commentary">For this to work we rely on the source template containing a <span class="extract"><span class="extract-syntax">&lt;/head&gt;</span></span> tag,
in exactly that casing and spacing, but that's safe enough for the templates
used by Inform.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::copy_html_line</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Websites::copy_html_line</span></span>:<br/><a href="3-wm.html#SP9">&#167;9</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line_r</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="identifier-syntax">state</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">PUT_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="character-syntax">'\n'</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::copy_html_line_r</span><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">match_results</span><span class="plain-syntax"> </span><span class="identifier-syntax">mr</span><span class="plain-syntax"> = </span><a href="../foundation/4-pm.html#SP9" class="function-link"><span class="function-syntax">Regexp::create_mr</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-pm.html#SP10" class="function-link"><span class="function-syntax">Regexp::match</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">"(%c*?)%[(%c*?)%](%c*)"</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line_r</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="identifier-syntax">state</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-plc.html#SP7" class="function-link"><span class="function-syntax">Placeholders::write</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[1]);</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line_r</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[2], </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="identifier-syntax">state</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="../foundation/4-pm.html#SP9" class="function-link"><span class="function-syntax">Regexp::dispose_of</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-pm.html#SP10" class="function-link"><span class="function-syntax">Regexp::match</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">"(%c*?)&lt;/head&gt;(%c*)"</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line_r</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="identifier-syntax">state</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-plc.html#SP7" class="function-link"><span class="function-syntax">Placeholders::write</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"INTERPRETERSCRIPTS"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;/head&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP10" class="function-link"><span class="function-syntax">Websites::copy_html_line_r</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[1], </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="identifier-syntax">state</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="../foundation/4-pm.html#SP9" class="function-link"><span class="function-syntax">Regexp::dispose_of</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Rendering the source text as HTML pages.</b>This is a fiddly operation, which requires us to parse the source text and
then typeset it appealingly in a whole suite of HTML pages. This necessarily
involves loops, but our main aim is to complete the process in \(O(N)\)
running time, where \(N\) is the number of lines in the source text. (Note
that the number of HTML files to be written will also be \(O(N)\).)
</p>

<p class="commentary">This is done in two passes. On pass 1, we scan the source text for tables
and headings, and divide the whole into "segments", each of which is
typeset as a single HTML page: segments do not quite correspond to headings,
as we shall see. But we write nothing. On pass 2, we actually write these
HTML pages.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">source_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::web_copy_source</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Websites::web_copy_source</span></span>:<br/>Releaser - <a href="3-rls.html#SP6_7">&#167;6.7</a>, <a href="3-rls.html#SP9_1">&#167;9.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="reserved-syntax">template</span><span class="plain-syntax">, </span><span class="reserved-syntax">pathname</span><span class="plain-syntax"> *</span><span class="identifier-syntax">website_pathname</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">source_text</span><span class="plain-syntax"> = </span><a href="../foundation/3-fln.html#SP3" class="function-link"><span class="function-syntax">Filenames::from_text</span></a><span class="plain-syntax">(</span><a href="3-plc.html#SP3" class="function-link"><span class="function-syntax">Placeholders::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SOURCELOCATION"</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP13" class="function-link"><span class="function-syntax">Websites::scan_source_text</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP15" class="function-link"><span class="function-syntax">Websites::write_source_text_pages</span></a><span class="plain-syntax">(</span><span class="reserved-syntax">template</span><span class="plain-syntax">, </span><span class="identifier-syntax">website_pathname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Pass 1: scanning the source for tables and headings.</b>During this scan, we will maintain the following variables:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">within_a_table</span><span class="plain-syntax">; </span><span class="comment-syntax"> are we inside a Table declaration in the source text?</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">scan_quoted_matter</span><span class="plain-syntax">; </span><span class="comment-syntax"> are we inside double-quoted matter in the source text?</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax">; </span><span class="comment-syntax"> level of nesting of comments in source text: 0 means "not in a comment"</span>
<span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">latest_line_position</span><span class="plain-syntax">; </span><span class="comment-syntax"> </span><span class="extract"><span class="extract-syntax">ftell</span></span><span class="comment-syntax">-reported byte offset of the start of the current line in the source</span>
<span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_table</span><span class="plain-syntax">; </span><span class="comment-syntax"> the Table which started most recently, or </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> if none has</span>
<span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_heading</span><span class="plain-syntax">; </span><span class="comment-syntax"> the heading seen most recently, or </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> if none has been</span>
<span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">; </span><span class="comment-syntax"> the segment which started most recently, or </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> if none has</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">; </span><span class="comment-syntax"> line count of the </span><span class="extract"><span class="extract-syntax">---- Documentation ----</span></span><span class="comment-syntax"> line, if there is one</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>Pass 1 has running time \(O(N)\) since it calls <span class="extract"><span class="extract-syntax">Websites::scan_source_line</span></span> exactly once
for each line in the source, and <span class="extract"><span class="extract-syntax">Websites::scan_source_line</span></span> looks only at a single line
and at the current table, heading and segment.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">MAX_SOURCE_TEXT_LINES</span><span class="plain-syntax"> </span><span class="constant-syntax">2000000000</span><span class="plain-syntax">; </span><span class="comment-syntax"> enough for 300 copies of the Linux kernel source &mdash; plenty!</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::scan_source_text</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Websites::scan_source_text</span></span>:<br/><a href="3-wm.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">within_a_table</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">scan_quoted_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_line_position</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax"> = </span><span class="constant-syntax">MAX_SOURCE_TEXT_LINES</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><a href="../foundation/4-tf.html#SP5" class="function-link"><span class="function-syntax">TextFiles::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">source_text</span><span class="plain-syntax">, </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><span class="string-syntax">"can't open source text of project"</span><span class="plain-syntax">, </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">, </span><a href="3-wm.html#SP14" class="function-link"><span class="function-syntax">Websites::scan_source_line</span></a><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP13_1" class="named-paragraph-link"><span class="named-paragraph">Adjust heading levels downwards as far as we can without losing relative hierarchy</span><span class="named-paragraph-number">13.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13_1" class="paragraph-anchor"></a><b>&#167;13.1. </b>Suppose our source contains only headings at levels 3 and 4: we can reduce these
to levels 0 and 1 without disturbing their relative importance, and that makes it
easier for us to typeset them in a sensible way &mdash; there's no point making any
typographic allowance for three sizes of headings greater than are found anywhere
in the source text.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Adjust heading levels downwards as far as we can without losing relative hierarchy</span><span class="named-paragraph-number">13.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">minhl</span><span class="plain-syntax"> = </span><span class="constant-syntax">10</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">h</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">h</span><span class="plain-syntax">, </span><span class="reserved-syntax">heading</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">minhl</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">minhl</span><span class="plain-syntax"> = </span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">h</span><span class="plain-syntax">, </span><span class="reserved-syntax">heading</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> -= </span><span class="identifier-syntax">minhl</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP13">&#167;13</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>Here we scan each single line. (Lines to us may look like whole paragraphs
to the Inform user; we're dealing with gaps between explicit line break
characters.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::scan_source_line</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Websites::scan_source_line</span></span>:<br/><a href="3-wm.html#SP13">&#167;13</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">lc</span><span class="plain-syntax"> = </span><a href="../foundation/4-tf.html#SP3" class="function-link"><span class="function-syntax">TextFiles::get_line_count</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">), </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">DULL_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_line_position</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">scan_quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP14_1" class="named-paragraph-link"><span class="named-paragraph">Look at the first word on the line to find the level of our interest</span><span class="named-paragraph-number">14.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> != </span><span class="constant-syntax">EMPTY_LEVEL</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">DULL_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP14_2" class="named-paragraph-link"><span class="named-paragraph">Correct the comment nesting level ready for next time</span><span class="named-paragraph-number">14.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">DULL_LEVEL</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">current_heading</span><span class="plain-syntax">)) </span><span class="identifier-syntax">current_heading</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_has_content</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">EMPTY_LEVEL</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">within_a_table</span><span class="plain-syntax">)) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP14_4" class="named-paragraph-link"><span class="named-paragraph">End a table here and return</span><span class="named-paragraph-number">14.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">TABLE_LEVEL</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP14_3" class="named-paragraph-link"><span class="named-paragraph">Start a new table here and return</span><span class="named-paragraph-number">14.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">EMPTY_LEVEL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">DULL_LEVEL</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax">) </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP14_5" class="named-paragraph-link"><span class="named-paragraph">Place a new heading here</span><span class="named-paragraph-number">14.5</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14_1" class="paragraph-anchor"></a><b>&#167;14.1. </b>Looking at the first word, if any, tells whether we are a heading, or the start
of a table, or an empty line, or none of these (in which case a line is perhaps
unfairly called "dull"). We set <span class="extract"><span class="extract-syntax">lv</span></span> accordingly.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">EMPTY_LEVEL</span><span class="plain-syntax"> -1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">DULL_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">1000</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">1001</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">EXAMPLE_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">1002</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">DOC_CHAPTER_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">1003</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">DOC_SECTION_LEVEL</span><span class="plain-syntax"> </span><span class="constant-syntax">1004</span>
</pre>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Look at the first word on the line to find the level of our interest</span><span class="named-paragraph-number">14.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">match_results</span><span class="plain-syntax"> </span><span class="identifier-syntax">mr</span><span class="plain-syntax"> = </span><a href="../foundation/4-pm.html#SP9" class="function-link"><span class="function-syntax">Regexp::create_mr</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-pm.html#SP10" class="function-link"><span class="function-syntax">Regexp::match</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">" *"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">EMPTY_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-pm.html#SP10" class="function-link"><span class="function-syntax">Regexp::match</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">" *(%C+)%c*?"</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"table"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">TABLE_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lc</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"chapter:"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">DOC_CHAPTER_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"section:"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">DOC_SECTION_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"example:"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">EXAMPLE_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"volume"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"book"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"part"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"chapter"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP22" class="function-link"><span class="function-syntax">Str::eq_wide_string</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">mr</span><span class="plain-syntax">.</span><span class="element-syntax">exp</span><span class="plain-syntax">[0], </span><span class="identifier-syntax">U</span><span class="string-syntax">"section"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-pm.html#SP10" class="function-link"><span class="function-syntax">Regexp::match</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">U</span><span class="string-syntax">" *---- documentation ---- *"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">lv</span><span class="plain-syntax"> = </span><span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="../foundation/4-pm.html#SP9" class="function-link"><span class="function-syntax">Regexp::dispose_of</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">mr</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14_2" class="paragraph-anchor"></a><b>&#167;14.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Correct the comment nesting level ready for next time</span><span class="named-paragraph-number">14.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">line</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="character-syntax">'['</span><span class="plain-syntax">) </span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="character-syntax">']'</span><span class="plain-syntax">) </span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">scan_comment_nesting</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="character-syntax">'\"'</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">scan_quoted_matter</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">scan_quoted_matter</span><span class="plain-syntax">)?</span><span class="identifier-syntax">FALSE:TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14_3" class="paragraph-anchor"></a><b>&#167;14.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Start a new table here and return</span><span class="named-paragraph-number">14.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">current_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_start</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_end</span><span class="plain-syntax"> = </span><span class="constant-syntax">MAX_SOURCE_TEXT_LINES</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">within_a_table</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14_4" class="paragraph-anchor"></a><b>&#167;14.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">End a table here and return</span><span class="named-paragraph-number">14.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">current_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_end</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">within_a_table</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP14_5" class="paragraph-anchor"></a><b>&#167;14.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Place a new heading here</span><span class="named-paragraph-number">14.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new_h</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">heading</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_text</span><span class="plain-syntax"> = </span><a href="../foundation/4-sm.html#SP3" class="function-link"><span class="function-syntax">Str::duplicate</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lv</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_line</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_has_content</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">current_heading</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">current_heading</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_has_content</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">lv</span><span class="plain-syntax"> == </span><span class="constant-syntax">DOC_LEVEL</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">) </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ends_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">segment</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">begins_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ends_at</span><span class="plain-syntax"> = </span><span class="constant-syntax">MAX_SOURCE_TEXT_LINES</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">start_position_in_file</span><span class="plain-syntax"> = *</span><span class="identifier-syntax">latest_line_position</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_heading</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lc</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">) </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_to_segment</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_segment</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_h</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP14">&#167;14</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. Pass 2: writing the source text pages.</b>Though there is no obvious way that the following routine passes control
to the routines below it, in fact it does: <span class="extract"><span class="extract-syntax">Websites::web_copy</span></span> works on the template
and finds reserved variables such as "[SOURCE]"; expanding those then calls
the routines below.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_doc_files</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_src_files</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::write_source_text_pages</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Websites::write_source_text_pages</span></span>:<br/><a href="3-wm.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="reserved-syntax">template</span><span class="plain-syntax">, </span><span class="reserved-syntax">pathname</span><span class="plain-syntax"> *</span><span class="identifier-syntax">website_pathname</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">, </span><span class="string-syntax">"%S.html"</span><span class="plain-syntax">, </span><a href="3-plc.html#SP3" class="function-link"><span class="function-syntax">Placeholders::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SOURCEPREFIX"</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">contents_page</span><span class="plain-syntax"> = </span><a href="../foundation/3-fln.html#SP2" class="function-link"><span class="function-syntax">Filenames::in</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">website_pathname</span><span class="plain-syntax">, </span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">)</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP15_1" class="named-paragraph-link"><span class="named-paragraph">Devise URLs for the segments</span><span class="named-paragraph-number">15.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP15_2" class="named-paragraph-link"><span class="named-paragraph">Work out how the segments link together</span><span class="named-paragraph-number">15.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP15_3" class="named-paragraph-link"><span class="named-paragraph">Generate the prefatory page, which isn't a segment</span><span class="named-paragraph-number">15.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP15_4" class="named-paragraph-link"><span class="named-paragraph">Generate the segment pages</span><span class="named-paragraph-number">15.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15_1" class="paragraph-anchor"></a><b>&#167;15.1. </b>Calling these URLs is a bit grand, since they are only leafnames. The
source segments have pages <span class="extract"><span class="extract-syntax">source_0.html</span></span> and so on up; the documentation
pages <span class="extract"><span class="extract-syntax">doc_0.html</span></span> and so on up.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Devise URLs for the segments</span><span class="named-paragraph-number">15.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="../foundation/4-sm.html#SP15" class="function-link"><span class="function-syntax">Str::clear</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">, </span><span class="string-syntax">"doc_%d.html"</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_doc_files</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">page_number</span><span class="plain-syntax"> = </span><span class="identifier-syntax">no_doc_files</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><a href="../foundation/4-sm.html#SP15" class="function-link"><span class="function-syntax">Str::clear</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">, </span><span class="string-syntax">"%S_%d.html"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><a href="3-plc.html#SP3" class="function-link"><span class="function-syntax">Placeholders::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SOURCEPREFIX"</span><span class="plain-syntax">), </span><span class="identifier-syntax">no_src_files</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">page_number</span><span class="plain-syntax"> = </span><span class="identifier-syntax">no_src_files</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP15_2" class="paragraph-anchor"></a><b>&#167;15.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Work out how the segments link together</span><span class="named-paragraph-number">15.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">seg</span><span class="plain-syntax">, *</span><span class="identifier-syntax">first_doc_seg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">first_src_seg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_doc_seg</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">first_doc_seg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_src_seg</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">first_src_seg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax"> = </span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"index.html"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax"> = </span><span class="identifier-syntax">first_doc_seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"index.html"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax"> = </span><span class="identifier-syntax">contents_leafname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">before</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="constant-syntax">TRUE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">before</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PREV_OBJECT</span><span class="plain-syntax">(</span><span class="identifier-syntax">before</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">before</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">before</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax"> == </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax"> = </span><span class="identifier-syntax">before</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">after</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="constant-syntax">TRUE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">after</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NEXT_OBJECT</span><span class="plain-syntax">(</span><span class="identifier-syntax">after</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">after</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">after</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax"> == </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">after</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP15_3" class="paragraph-anchor"></a><b>&#167;15.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate the prefatory page, which isn't a segment</span><span class="named-paragraph-number">15.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">source_HTML_pages_created</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP9" class="function-link"><span class="function-syntax">Websites::web_copy</span></a><span class="plain-syntax">(</span><span class="reserved-syntax">template</span><span class="plain-syntax">, </span><span class="identifier-syntax">contents_page</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP15_4" class="paragraph-anchor"></a><b>&#167;15.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate the segment pages</span><span class="named-paragraph-number">15.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">seg</span><span class="plain-syntax">, </span><span class="reserved-syntax">segment</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">segment_page</span><span class="plain-syntax"> = </span><a href="../foundation/3-fln.html#SP2" class="function-link"><span class="function-syntax">Filenames::in</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">website_pathname</span><span class="plain-syntax">, </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> = </span><span class="identifier-syntax">seg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">source_HTML_pages_created</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP9" class="function-link"><span class="function-syntax">Websites::web_copy</span></a><span class="plain-syntax">(</span><span class="reserved-syntax">template</span><span class="plain-syntax">, </span><span class="identifier-syntax">segment_page</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>This is what "[PAGENUMBER]" in the template becomes.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::expand_PAGENUMBER_variable</span><button class="popup" onclick="togglePopup('usagePopup16')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup16">Usage of <span class="code-font"><span class="function-syntax">Websites::expand_PAGENUMBER_variable</span></span>:<br/>Placeholders - <a href="3-plc.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">p</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">p</span><span class="plain-syntax"> = </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">page_number</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) </span><span class="identifier-syntax">p</span><span class="plain-syntax">++; </span><span class="comment-syntax"> allow for header page</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"%d"</span><span class="plain-syntax">, </span><span class="identifier-syntax">p</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. </b>And similarly "[PAGEEXTENT]".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::expand_PAGEEXTENT_variable</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">Websites::expand_PAGEEXTENT_variable</span></span>:<br/>Placeholders - <a href="3-plc.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">no_src_files</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">documentation</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">no_doc_files</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"%d"</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18" class="paragraph-anchor"></a><b>&#167;18. </b>And this is what "[SOURCELINKS]" in the template becomes:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::expand_SOURCELINKS_variable</span><button class="popup" onclick="togglePopup('usagePopup18')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup18">Usage of <span class="code-font"><span class="function-syntax">Websites::expand_SOURCELINKS_variable</span></span>:<br/>Placeholders - <a href="3-plc.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">seg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S\"&gt;Home page&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_home</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S\"&gt;Beginning&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_contents</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S\"&gt;Previous&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_previous</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_next</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S\"&gt;Next&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">seg</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">link_next</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"index.html\"&gt;Home page&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYTO</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S.txt\"&gt;Complete text&lt;/a&gt;&lt;/li&gt;"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><a href="3-plc.html#SP3" class="function-link"><span class="function-syntax">Placeholders::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SOURCEPREFIX"</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP19" class="paragraph-anchor"></a><b>&#167;19. </b>When working on "[SOURCE]" or "[SOURCENOTES]", we will need to run
through a segment of the source text, one line at a time. As we do so, we'll
maintain the following variables, along with <span class="extract"><span class="extract-syntax">current_style</span></span> (for which
see the CSS discussion above):
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="comment-syntax"> where the output is going</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">SOURCENOTES_mode</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> </span><span class="extract"><span class="extract-syntax">TRUE</span></span><span class="comment-syntax"> for "[SOURCENOTES]", </span><span class="extract"><span class="extract-syntax">FALSE</span></span><span class="comment-syntax"> for "[SOURCE]"</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> are we inside double-quoted matter in the source text?</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> are we inside verbatim I6 code in the source text?</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax"> nesting level of comments in source text being read: 0 for not in a comment</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax"> ditto, but where the outermost comment is a footnote marker</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax"> = -1; </span><span class="comment-syntax"> indentation carried over for para breaks in quoted text</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> number to assign to the next footnote which comes up</span>
<span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="comment-syntax"> a heading which is always behind the current position</span>
<span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">latest_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="comment-syntax"> a table which is always behind the current position</span>
</pre>
<p class="commentary firstcommentary"><a id="SP20" class="paragraph-anchor"></a><b>&#167;20. </b>So this is "[SOURCE]" (if <span class="extract"><span class="extract-syntax">noting_mode</span></span> is <span class="extract"><span class="extract-syntax">FALSE</span></span>) or "[SOURCENOTES]"
(if <span class="extract"><span class="extract-syntax">TRUE</span></span>).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::expand_SOURCE_or_SOURCENOTES_variable</span><button class="popup" onclick="togglePopup('usagePopup19')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup19">Usage of <span class="code-font"><span class="function-syntax">Websites::expand_SOURCE_or_SOURCENOTES_variable</span></span>:<br/>Placeholders - <a href="3-plc.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">SN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">SN</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP20_2" class="named-paragraph-link"><span class="named-paragraph">Typeset the little Notes subheading</span><span class="named-paragraph-number">20.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP6" class="function-link"><span class="function-syntax">Websites::open_code</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP20_1" class="named-paragraph-link"><span class="named-paragraph">Initialise the variables to their state at the start of an HTML page</span><span class="named-paragraph-number">20.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP20_3" class="named-paragraph-link"><span class="named-paragraph">Read the source text and feed it one line at a time to the line-writer</span><span class="named-paragraph-number">20.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP6" class="function-link"><span class="function-syntax">Websites::close_code</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP20_1" class="paragraph-anchor"></a><b>&#167;20.1. </b>So at the start of the preface or of any segment:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Initialise the variables to their state at the start of an HTML page</span><span class="named-paragraph-number">20.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax"> = </span><span class="identifier-syntax">OUT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">SOURCENOTES_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_style</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FIRST_OBJECT</span><span class="plain-syntax">(</span><span class="reserved-syntax">heading</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FIRST_OBJECT</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP20">&#167;20</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP20_2" class="paragraph-anchor"></a><b>&#167;20.2. </b>We expect any use of "[SOURCENOTES]" to come after the relevant
"[SOURCE]", so that looking at <span class="extract"><span class="extract-syntax">next_footnote_number</span></span> will tell us how many
notes there were.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset the little Notes subheading</span><span class="named-paragraph-number">20.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">; </span><span class="comment-syntax"> there were no footnotes at all</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;p&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="string-syntax">"notesheading"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"Note"</span><span class="plain-syntax">); </span><span class="comment-syntax"> just one</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"Notes"</span><span class="plain-syntax">); </span><span class="comment-syntax"> more than one</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="string-syntax">"notesheading"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;/p&gt;\n"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP20">&#167;20</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP20_3" class="paragraph-anchor"></a><b>&#167;20.3. </b>We want to be very careful about running time here. This paragraph will
run about \(H\) times, where \(H\) is the number of headings (in fact at most \(H+1\)
times and usually a little less); but we might reasonably expect that \(H\)
is proportional to \(N\), since there's typically a heading every 30 or so
lines in the source text, so that H is about N/30. If we then did the simplest
thing, of opening the source text file and sending every line to
<span class="extract"><span class="extract-syntax">Websites::write_source_line</span></span>, we would make \(O(N^2)\) calls, and even though many of
those would quickly return it would be an expensive algorithm.
</p>

<p class="commentary">Instead, we start at the relevant position in the source text for the
current HTML page, and we stop the moment that <span class="extract"><span class="extract-syntax">Websites::write_source_line</span></span> reports
that it has gone past the material of interest. We thus make at most \(N+H\)
calls to <span class="extract"><span class="extract-syntax">Websites::write_source_line</span></span> (the extra \(H\) calls being for one overspill line
per segment, where we realise that we've gone too far).
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the source text and feed it one line at a time to the line-writer</span><span class="named-paragraph-number">20.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">start</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP20_3_1" class="named-paragraph-link"><span class="named-paragraph">Start from just the right place in the source file</span><span class="named-paragraph-number">20.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="../foundation/4-tf.html#SP5" class="function-link"><span class="function-syntax">TextFiles::read</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">source_text</span><span class="plain-syntax">, </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><span class="string-syntax">"can't open source text"</span><span class="plain-syntax">, </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP21" class="function-link"><span class="function-syntax">Websites::source_write_iterator</span></a><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP20">&#167;20</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP20_3_1" class="paragraph-anchor"></a><b>&#167;20.3.1. </b>The following simulates the effect of running through the uninteresting lines
before the segment begins:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Start from just the right place in the source file</span><span class="named-paragraph-number">20.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">start</span><span class="plain-syntax"> = &amp;(</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">start_position_in_file</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_heading</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_heading</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">most_recent_table</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP20_3">&#167;20.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP21" class="paragraph-anchor"></a><b>&#167;21. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::source_write_iterator</span><button class="popup" onclick="togglePopup('usagePopup20')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup20">Usage of <span class="code-font"><span class="function-syntax">Websites::source_write_iterator</span></span>:<br/><a href="3-wm.html#SP20_3">&#167;20.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">done_yet</span><span class="plain-syntax"> = </span><a href="3-wm.html#SP22" class="function-link"><span class="function-syntax">Websites::write_source_line</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">tfp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">done_yet</span><span class="plain-syntax">) </span><a href="../foundation/4-tf.html#SP7" class="function-link"><span class="function-syntax">TextFiles::lose_interest</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22" class="paragraph-anchor"></a><b>&#167;22. </b>And this is where we write lines. We arrive here with exactly the same line
count as the scanner observed before on pass 1, so we can validly compare
our current line count against those stored for tables, headings and segments.
</p>

<p class="commentary">When this routine returns <span class="extract"><span class="extract-syntax">TRUE</span></span>, it signals that there is no further need for
the source text, and that saves reading in all of the remaining lines which
won't be needed.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::write_source_line</span><button class="popup" onclick="togglePopup('usagePopup21')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup21">Usage of <span class="code-font"><span class="function-syntax">Websites::write_source_line</span></span>:<br/><a href="3-wm.html#SP21">&#167;21</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> = </span><a href="../foundation/4-tf.html#SP3" class="function-link"><span class="function-syntax">TextFiles::get_line_count</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_1" class="named-paragraph-link"><span class="named-paragraph">Filter out lines for the preface</span><span class="named-paragraph-number">22.1</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_2" class="named-paragraph-link"><span class="named-paragraph">Filter out lines for the segments</span><span class="named-paragraph-number">22.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">SOURCENOTES_mode</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_3" class="named-paragraph-link"><span class="named-paragraph">Typeset the line in [SOURCENOTES] mode</span><span class="named-paragraph-number">22.3</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4" class="named-paragraph-link"><span class="named-paragraph">Typeset the line in [SOURCE] mode</span><span class="named-paragraph-number">22.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22_1" class="paragraph-anchor"></a><b>&#167;22.1. </b>Recall that the source text is divided into an initial portion containing
no headings &mdash; the "preface" &mdash; and then segments, each of which begins with
a heading.
</p>

<p class="commentary">Here we are handling the case of typesetting the preface. We allow the line
to appear as normal if it is before the first segment; once we reach the
first segment &mdash; if there's a first segment to reach &mdash; we then typeset the
contents listing. (If there's no first segment, then there are no headings,
and there's no need for a contents listing.) If we've output the contents
listing then we are finished writing the preface and don't need to read the
source text further, so we return <span class="extract"><span class="extract-syntax">TRUE</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Filter out lines for the preface</span><span class="named-paragraph-number">22.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">segment</span><span class="plain-syntax"> *</span><span class="identifier-syntax">first_segment</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FIRST_OBJECT</span><span class="plain-syntax">(</span><span class="reserved-syntax">segment</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">first_segment</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">first_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">begins_at</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP8" class="function-link"><span class="function-syntax">Str::len</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">; </span><span class="comment-syntax"> don't bother to typeset a blank line just before the first segment is reached</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">first_segment</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">first_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">begins_at</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">SOURCENOTES_mode</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) </span><a href="3-wm.html#SP23" class="function-link"><span class="function-syntax">Websites::typeset_contents_listing</span></a><span class="plain-syntax">(</span><span class="constant-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_2" class="paragraph-anchor"></a><b>&#167;22.2. </b>The segment pages are easier: in this case we allow the line only if it
lies inside the segment, and otherwise suppress it. Once we've gone beyond
the segment, we don't need to read any further, so we return <span class="extract"><span class="extract-syntax">TRUE</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Filter out lines for the segments</span><span class="named-paragraph-number">22.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">begins_at</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ends_at</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP23" class="function-link"><span class="function-syntax">Websites::typeset_contents_listing</span></a><span class="plain-syntax">(</span><span class="constant-syntax">FALSE</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_3" class="paragraph-anchor"></a><b>&#167;22.3. </b>In [SOURCENOTES] mode, we detect footnotes in the form of comments in the
source text marked by asterisks; each one is assigned the next footnote
number, and typeset. All other material is ignored.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset the line in [SOURCENOTES] mode</span><span class="named-paragraph-number">22.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">L</span><span class="plain-syntax"> = </span><a href="../foundation/4-sm.html#SP8" class="function-link"><span class="function-syntax">Str::len</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">'['</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">'*'</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;p&gt;&lt;a name=\"note%d\"&gt;&lt;/a&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"notetext"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;a href=\"#note%dref\"&gt;[%d]&lt;/a&gt;. "</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">, </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">i</span><span class="plain-syntax">+=2;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">'['</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">']'</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"notetext"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;/p&gt;\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"%c"</span><span class="plain-syntax">, </span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">" "</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4" class="paragraph-anchor"></a><b>&#167;22.4. </b>In [SOURCE] mode, we need to work out appropriate type styles to embellish
the line, then indent it suitably, then typeset it character by character.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset the line in [SOURCE] mode</span><span class="named-paragraph-number">22.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">embolden</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><span class="identifier-syntax">tabulate</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">, </span><span class="identifier-syntax">underline</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_3" class="named-paragraph-link"><span class="named-paragraph">Decide any typographic embellishments due to the line falling inside a table</span><span class="named-paragraph-number">22.4.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_4" class="named-paragraph-link"><span class="named-paragraph">The top line of the preface or any segment is in bold</span><span class="named-paragraph-number">22.4.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_5" class="named-paragraph-link"><span class="named-paragraph">Any heading line is in bold</span><span class="named-paragraph-number">22.4.5</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">tabulate</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;tr&gt;"</span><span class="plain-syntax">); </span><a href="3-wm.html#SP8" class="function-link"><span class="function-syntax">Websites::open_table_cell</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">start</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (; </span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">); </span><span class="identifier-syntax">start</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">) == </span><span class="character-syntax">'['</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">) == </span><span class="character-syntax">']'</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="identifier-syntax">start</span><span class="plain-syntax">++; </span><span class="reserved-syntax">break</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tabulate</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">insteps</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (; </span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">) == </span><span class="character-syntax">'\t'</span><span class="plain-syntax">; </span><span class="identifier-syntax">start</span><span class="plain-syntax">++) </span><span class="identifier-syntax">insteps</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">insteps</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><a href="3-wm.html#SP7" class="function-link"><span class="function-syntax">Websites::open_code_paragraph</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>

<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_1" class="named-paragraph-link"><span class="named-paragraph">Begin typographic embellishments</span><span class="named-paragraph-number">22.4.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_6" class="named-paragraph-link"><span class="named-paragraph">The documentation requires some corrections</span><span class="named-paragraph-number">22.4.6</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=</span><span class="identifier-syntax">start</span><span class="plain-syntax">, </span><span class="identifier-syntax">L</span><span class="plain-syntax">=</span><a href="../foundation/4-sm.html#SP8" class="function-link"><span class="function-syntax">Str::len</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7" class="named-paragraph-link"><span class="named-paragraph">Typeset a single character of the source text</span><span class="named-paragraph-number">22.4.7</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_2" class="named-paragraph-link"><span class="named-paragraph">End typographic embellishments</span><span class="named-paragraph-number">22.4.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">tabulate</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><a href="3-wm.html#SP8" class="function-link"><span class="function-syntax">Websites::close_table_cell</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">); </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;/tr&gt;\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><a href="3-wm.html#SP7" class="function-link"><span class="function-syntax">Websites::close_code_paragraph</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) </span><span class="identifier-syntax">carry_over_indentation</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_1" class="paragraph-anchor"></a><b>&#167;22.4.1. </b>The type styles are easily applied, so let's do that now. The innermost one
must be colour, since that may change in the course of the line.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Begin typographic embellishments</span><span class="named-paragraph-number">22.4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">underline</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"columnhead"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">embolden</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"heading"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_style</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_style</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a> and <a href="3-wm.html#SP22_4_7_1">&#167;22.4.7.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_2" class="paragraph-anchor"></a><b>&#167;22.4.2. </b>And they end in reverse order, so that they nest properly if need be:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">End typographic embellishments</span><span class="named-paragraph-number">22.4.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_style</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_style</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">embolden</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"heading"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">underline</span><span class="plain-syntax">) </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"columnhead"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a> and <a href="3-wm.html#SP22_4_7_1">&#167;22.4.7.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_3" class="paragraph-anchor"></a><b>&#167;22.4.3. </b>The heading line of a source text Table is in bold; the column-headings
line is underlined; and the material inside appears in an HTML table, with
<span class="extract"><span class="extract-syntax">tabulate</span></span> mode set.
</p>

<p class="commentary">The <span class="extract"><span class="extract-syntax">while</span></span> loop here needs a careful look, since on the face of it this
could mean \(O(N)\) iterations &mdash; since the number of tables is probably
proportional to \(N\) &mdash; made in the course of the current "[SOURCE]"
expansion. Since the number of "[SOURCE]" expansions needed to make the
website is also \(O(N)\) &mdash; the number of HTML pages in the site is proportional
to the number of headings, which is also proportional to \(N\) &mdash; there's a
risk that this <span class="extract"><span class="extract-syntax">while</span></span> loop makes the whole website algorithm \(O(N^2)\).
This is why, on each "[SOURCE]" expansion, <span class="extract"><span class="extract-syntax">latest_table</span></span> is initialised
not to the first table but to the most recent one at the start position of
the current HTML page. Moreover, the loop never goes past the current line
count, which never goes outside the range of lines in the current HTML page.
The result is that over the course of all the "[SOURCE]" expansions
combined, the <span class="extract"><span class="extract-syntax">while</span></span> loop here executes \(O(N)\) iterations in total.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Decide any typographic embellishments due to the line falling inside a table</span><span class="named-paragraph-number">22.4.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_end</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">line_count</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NEXT_OBJECT</span><span class="plain-syntax">(</span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> = </span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_start</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">latest_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_line_end</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">from</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">embolden</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">from</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">to</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">tabulate</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">from</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">underline</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;table&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">to</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;/table&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_4" class="paragraph-anchor"></a><b>&#167;22.4.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">The top line of the preface or any segment is in bold</span><span class="named-paragraph-number">22.4.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">segment_being_written</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">begins_at</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">embolden</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_5" class="paragraph-anchor"></a><b>&#167;22.4.5. </b>See the discussion of <span class="extract"><span class="extract-syntax">latest_table</span></span> above for why the following <span class="extract"><span class="extract-syntax">while</span></span>
loop also doesn't make our algorithm \(O(N^2)\).
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Any heading line is in bold</span><span class="named-paragraph-number">22.4.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_line</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">line_count</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NEXT_OBJECT</span><span class="plain-syntax">(</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax">, </span><span class="reserved-syntax">heading</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">latest_heading</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_line</span><span class="plain-syntax"> == </span><span class="identifier-syntax">line_count</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">embolden</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_6" class="paragraph-anchor"></a><b>&#167;22.4.6. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">The documentation requires some corrections</span><span class="named-paragraph-number">22.4.6</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">) == </span><span class="character-syntax">'*'</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">+1) == </span><span class="character-syntax">':'</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">start</span><span class="plain-syntax">+2) == </span><span class="character-syntax">' '</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">start</span><span class="plain-syntax"> += </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line_count</span><span class="plain-syntax"> == </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">) </span><a href="../foundation/4-sm.html#SP17" class="function-link"><span class="function-syntax">Str::copy</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Documentation"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7" class="paragraph-anchor"></a><b>&#167;22.4.7. </b>We need to do two things: ensure that the character is HTML-safe, which
means escaping out <span class="extract"><span class="extract-syntax">"</span></span>, <span class="extract"><span class="extract-syntax">&lt;</span></span>, <span class="extract"><span class="extract-syntax">&gt;</span></span> and <span class="extract"><span class="extract-syntax">&amp;</span></span> (but nothing else since the HTML
file will use a UTF-8 encoding, the same as that in the source text); and
keep track of the opening and closing of comments and quoted matter.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset a single character of the source text</span><span class="named-paragraph-number">22.4.7</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'\t'</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="comment-syntax"> a multiple tab is equivalent to a single tab in Inform source text</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">'\t'</span><span class="plain-syntax">) </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_1" class="named-paragraph-link"><span class="named-paragraph">Typeset a tab</span><span class="named-paragraph-number">22.4.7.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'"'</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax">)) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&amp;quot;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_2" class="named-paragraph-link"><span class="named-paragraph">Typeset a double quotation mark outside of a comment</span><span class="named-paragraph-number">22.4.7.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'['</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax">) { </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"["</span><span class="plain-syntax">); </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"substitution"</span><span class="plain-syntax">); }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"["</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_3" class="named-paragraph-link"><span class="named-paragraph">Typeset an open square bracket outside of a string</span><span class="named-paragraph-number">22.4.7.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">']'</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax">) { </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"quote"</span><span class="plain-syntax">); </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"]"</span><span class="plain-syntax">); }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"]"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_4" class="named-paragraph-link"><span class="named-paragraph">Typeset a close square bracket outside of a string</span><span class="named-paragraph-number">22.4.7.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'('</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">                (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">'-'</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_5" class="named-paragraph-link"><span class="named-paragraph">Typeset the opening of I6 verbatim code</span><span class="named-paragraph-number">22.4.7.5</span></a></span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'-'</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax">) &amp;&amp; (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">')'</span><span class="plain-syntax">)) { </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_6" class="named-paragraph-link"><span class="named-paragraph">Typeset the closing of I6 verbatim code</span><span class="named-paragraph-number">22.4.7.6</span></a></span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"-"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'&lt;'</span><span class="plain-syntax">: </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&amp;lt;"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'&gt;'</span><span class="plain-syntax">: </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&amp;gt;"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'&amp;'</span><span class="plain-syntax">: </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&amp;amp;"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"%c"</span><span class="plain-syntax">, </span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">)); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4">&#167;22.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_1" class="paragraph-anchor"></a><b>&#167;22.4.7.1. </b>Inside a source-text Table, a tab moves to the next column, so we need to typeset a
cell boundary in our HTML <span class="extract"><span class="extract-syntax">&lt;table&gt;</span></span>. Outside of that context, a tab is just white
space and we turn it into a single space.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset a tab</span><span class="named-paragraph-number">22.4.7.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tabulate</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_2" class="named-paragraph-link"><span class="named-paragraph">End typographic embellishments</span><span class="named-paragraph-number">22.4.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP8" class="function-link"><span class="function-syntax">Websites::close_table_cell</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-wm.html#SP8" class="function-link"><span class="function-syntax">Websites::open_table_cell</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_1" class="named-paragraph-link"><span class="named-paragraph">Begin typographic embellishments</span><span class="named-paragraph-number">22.4.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">" "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_2" class="paragraph-anchor"></a><b>&#167;22.4.7.2. </b>The following enters or exits quoted-matter mode, and is structured so that
the quotation marks are not coloured &mdash; only the material inside them.
</p>

<p class="commentary">Our code in handling quoted and comment matter is greatly simplified by the
fact that a valid Inform text cannot contain mismatched square brackets;
however, as Dave Chapeskie points out, a valid comment can contain mismatched
quotation marks, and this section of code benefits from his careful amendments.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset a double quotation mark outside of a comment</span><span class="named-paragraph-number">22.4.7.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax">) </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&amp;quot;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"quote"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">quoted_matter</span><span class="plain-syntax">)?</span><span class="identifier-syntax">FALSE:TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_3" class="paragraph-anchor"></a><b>&#167;22.4.7.3. </b>On the other hand, the squares around a comment do pick up the colour
of the commentary within them. Asterisked comments must end in the same paragraph
as they begin.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset an open square bracket outside of a string</span><span class="named-paragraph-number">22.4.7.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">'*'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="comment-syntax"> advance past the end of the asterisked comment</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">+=2, </span><span class="identifier-syntax">L</span><span class="plain-syntax">=</span><a href="../foundation/4-sm.html#SP8" class="function-link"><span class="function-syntax">Str::len</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; ++</span><span class="identifier-syntax">i</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">'['</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">']'</span><span class="plain-syntax">) </span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">footnote_comment_level</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="../foundation/4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">line</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">i</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP22_4_7_3_1" class="named-paragraph-link"><span class="named-paragraph">Typeset a footnote cue</span><span class="named-paragraph-number">22.4.7.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"comment"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"["</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_4" class="paragraph-anchor"></a><b>&#167;22.4.7.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset a close square bracket outside of a string</span><span class="named-paragraph-number">22.4.7.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"]"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">comment_nesting</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_5" class="paragraph-anchor"></a><b>&#167;22.4.7.5. </b>Styling applied to I6 verbatim code does not apply to the purely-I7 markers
"(-" and "-)" around it:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset the opening of I6 verbatim code</span><span class="named-paragraph-number">22.4.7.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"(-"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"i6code"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_6" class="paragraph-anchor"></a><b>&#167;22.4.7.6. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset the closing of I6 verbatim code</span><span class="named-paragraph-number">22.4.7.6</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="3-wm.html#SP5" class="function-link"><span class="function-syntax">Websites::change_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"-)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i6_matter</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7">&#167;22.4.7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4_7_3_1" class="paragraph-anchor"></a><b>&#167;22.4.7.3.1. </b>The "cue" of a footnote is the reference in the body of the text, which
is conventionally printed as a superscript number. We leave that to the
span <span class="extract"><span class="extract-syntax">notecue</span></span> if we have CSS, and otherwise render in grey superscript.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typeset a footnote cue</span><span class="named-paragraph-number">22.4.7.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;a name=\"note%dref\"&gt;&lt;/a&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::open_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"notecue"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;a href=\"#note%d\"&gt;[%d]&lt;/a&gt;"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">, </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-wm.html#SP4" class="function-link"><span class="function-syntax">Websites::close_style</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"notecue"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">next_footnote_number</span><span class="plain-syntax">++;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP22_4_7_3">&#167;22.4.7.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP23" class="paragraph-anchor"></a><b>&#167;23. </b>That just leaves the little contents listings &mdash; one for the source, and
another for the documentation (if any).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Websites::typeset_contents_listing</span><button class="popup" onclick="togglePopup('usagePopup22')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup22">Usage of <span class="code-font"><span class="function-syntax">Websites::typeset_contents_listing</span></span>:<br/><a href="3-wm.html#SP22_1">&#167;22.1</a>, <a href="3-wm.html#SP22_2">&#167;22.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">source_contents</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">benchmark_level</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">source_contents</span><span class="plain-syntax">)?0:</span><span class="constant-syntax">DOC_CHAPTER_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_level</span><span class="plain-syntax"> = </span><span class="identifier-syntax">benchmark_level</span><span class="plain-syntax">-1, </span><span class="identifier-syntax">new_level</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">heading</span><span class="plain-syntax"> *</span><span class="identifier-syntax">h</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">h</span><span class="plain-syntax">, </span><span class="reserved-syntax">heading</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">source_contents</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_line</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">            ((</span><span class="identifier-syntax">source_contents</span><span class="plain-syntax"> == </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_line</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">position_of_documentation_bar</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">new_level</span><span class="plain-syntax"> = </span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_level</span><span class="plain-syntax"> == </span><span class="constant-syntax">EXAMPLE_LEVEL</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_level</span><span class="plain-syntax"> = </span><span class="constant-syntax">DOC_CHAPTER_LEVEL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP23_1" class="named-paragraph-link"><span class="named-paragraph">Open or close UL tags to move to the new heading level</span><span class="named-paragraph-number">23.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;li&gt;&lt;a href=\"%S\"&gt;%S&lt;/a&gt;&lt;/li&gt;\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_to_segment</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">segment_url</span><span class="plain-syntax">, </span><span class="identifier-syntax">h</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">heading_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_level</span><span class="plain-syntax"> = </span><span class="identifier-syntax">benchmark_level</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-wm.html#SP23_1" class="named-paragraph-link"><span class="named-paragraph">Open or close UL tags to move to the new heading level</span><span class="named-paragraph-number">23.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP23_1" class="paragraph-anchor"></a><b>&#167;23.1. </b>This is how we obtain our nested UL tags: <span class="extract"><span class="extract-syntax">current_level</span></span> starts and ends at
\(b-1\), and can only change its value by executing the following loops. Since
it never changes to a value lower than 0 except when returning to \(b-1\) at
the end, we are always inside at least the outermost <span class="extract"><span class="extract-syntax">&lt;ul&gt;</span></span>, and since the
net change over the whole process is 0, there must be as many steps upward
as downward &mdash; so every <span class="extract"><span class="extract-syntax">&lt;ul&gt;</span></span> is closed by a matching <span class="extract"><span class="extract-syntax">&lt;/ul&gt;</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Open or close UL tags to move to the new heading level</span><span class="named-paragraph-number">23.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_level</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">current_level</span><span class="plain-syntax">) { </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;ul&gt;"</span><span class="plain-syntax">); </span><span class="identifier-syntax">current_level</span><span class="plain-syntax">++; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_level</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">current_level</span><span class="plain-syntax">) { </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">SPAGE</span><span class="plain-syntax">, </span><span class="string-syntax">"&lt;/ul&gt;"</span><span class="plain-syntax">); </span><span class="identifier-syntax">current_level</span><span class="plain-syntax">--; }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-wm.html#SP23">&#167;23</a> (twice).</li></ul>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="3-tmp.html">&#10094;</a></li><li class="progresschapter"><a href="M-ui.html">M</a></li><li class="progresschapter"><a href="1-bsc.html">1</a></li><li class="progresschapter"><a href="2-bw.html">2</a></li><li class="progresscurrentchapter">3</li><li class="progresssection"><a href="3-rls.html">rls</a></li><li class="progresssection"><a href="3-sd.html">sd</a></li><li class="progresssection"><a href="3-laaf.html">laaf</a></li><li class="progresssection"><a href="3-plc.html">plc</a></li><li class="progresssection"><a href="3-tmp.html">tmp</a></li><li class="progresscurrent">wm</li><li class="progresssection"><a href="3-bs6.html">bs6</a></li><li class="progressnext"><a href="3-bs6.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

